package com.ffapp.demo.chemicals;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ffapp.demo.R;
import com.ffapp.demo.basis.BasisActivity;
import com.ffapp.demo.bean.BaseListData;
import com.ffapp.demo.bean.BaseListDataListBean;
import com.ffapp.demo.bean.ChemicalData;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ChemicalInfoActivity extends BasisActivity {

    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;

    ChemicalData chemicalData;
    private BaseListDataListBean baseListBean;

    public static void toActivity(Activity activity, ChemicalData data) {
        Intent intent = new Intent(activity, ChemicalInfoActivity.class);
        intent.putExtra("data", data);
        activity.startActivity(intent);
    }


    @Override
    public void initViews() {
        super.initViews();
        setContentView(R.layout.base_recycler_with_top);
        setTitle("危化品详情 ");
        setTitleLeftButton(null);
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);
    }


    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        chemicalData = (ChemicalData) getIntent().getSerializableExtra("data");
        if (chemicalData == null) {
            showToast(R.string.app_data_empty);
            return;
        }
        getList();
    }

    public void getList() {

        baseListBean = new BaseListDataListBean();
        baseListBean.getList().add(new BaseListData("化学品类别", chemicalData.getHxplb()));
        baseListBean.getList().add(new BaseListData("CAS编号", chemicalData.getCasNo()));
        baseListBean.getList().add(new BaseListData("UN编号", chemicalData.getUnNo()));
        baseListBean.getList().add(new BaseListData("名称", chemicalData.getCnname()));
        baseListBean.getList().add(new BaseListData("英文名称:", chemicalData.getEnname()));
        baseListBean.getList().add(new BaseListData("其他名称:", chemicalData.getQtname()));
        baseListBean.getList().add(new BaseListData("参照处置方案:", chemicalData.getCzczfa()));
        baseListBean.getList().add(new BaseListData("参照危学品:", chemicalData.getCzhxp()));
        baseListBean.getList().add(new BaseListData("重要警示:", chemicalData.getWarning()));
        baseListBean.getList().add(new BaseListData("理化特性/一般说明:", chemicalData.getLhtx()));
        baseListBean.getList().add(new BaseListData("气味:", chemicalData.getQw()));
        baseListBean.getList().add(new BaseListData("颜色:", chemicalData.getYs()));
        baseListBean.getList().add(new BaseListData("状态:", chemicalData.getStatus()));
        baseListBean.getList().add(new BaseListData("沸点:", chemicalData.getFd()));
        baseListBean.getList().add(new BaseListData("闪点:", chemicalData.getSd()));
        baseListBean.getList().add(new BaseListData("相对水密度(水=1):", chemicalData.getXdsmd()));
        baseListBean.getList().add(new BaseListData("熔点:", chemicalData.getRd()));
        baseListBean.getList().add(new BaseListData("爆炸极限(高):", chemicalData.getBzjxHigh()));
        baseListBean.getList().add(new BaseListData("爆炸极限(低):", chemicalData.getBzjxLow()));
        baseListBean.getList().add(new BaseListData("相对空气密度（空气  = 1）:", chemicalData.getXdkqmd()));
        baseListBean.getList().add(new BaseListData("危险性:", chemicalData.getWxx()));
        baseListBean.getList().add(new BaseListData("燃烧分解产物:", chemicalData.getRsfjcw()));
        baseListBean.getList().add(new BaseListData("储存包装:", chemicalData.getCcbz()));
        baseListBean.getList().add(new BaseListData("禁忌物:", chemicalData.getJjw()));
        baseListBean.getList().add(new BaseListData("皮肤:", chemicalData.getSkin()));
        baseListBean.getList().add(new BaseListData("眼:", chemicalData.getEye()));
        baseListBean.getList().add(new BaseListData("呼吸道:", chemicalData.getHxd()));
        baseListBean.getList().add(new BaseListData("窒息症状:", chemicalData.getZxzz()));
        baseListBean.getList().add(new BaseListData("中枢神经系统:", chemicalData.getZssjxt()));
        baseListBean.getList().add(new BaseListData("呼吸系统:", chemicalData.getHxxt()));
        baseListBean.getList().add(new BaseListData("循环系统:", chemicalData.getXhxt()));
        baseListBean.getList().add(new BaseListData("消化系统:", chemicalData.getXiaohuaxt()));
        baseListBean.getList().add(new BaseListData("大鼠经口LD50:", chemicalData.getLd50()));
        baseListBean.getList().add(new BaseListData("小鼠吸入LC50:", chemicalData.getLc50()));
        baseListBean.getList().add(new BaseListData("致癌性:", chemicalData.getZax()));
        baseListBean.getList().add(new BaseListData("危险分类:", chemicalData.getClassify()));
        baseListBean.getList().add(new BaseListData("UN危险分类:", chemicalData.getUnClassify()));
        baseListBean.getList().add(new BaseListData("物理危害:", chemicalData.getWlwh()));
        baseListBean.getList().add(new BaseListData("健康危害:", chemicalData.getJkwh()));
        baseListBean.getList().add(new BaseListData("环境危害:", chemicalData.getHjwh()));
        baseListBean.getList().add(new BaseListData("初始隔离半径:", chemicalData.getCsglbj()));
        baseListBean.getList().add(new BaseListData("下风向疏散距离:", chemicalData.getXfxssjl()));
        baseListBean.getList().add(new BaseListData("火灾疏散半径:", chemicalData.getHzssbj()));
        baseListBean.getList().add(new BaseListData("防护装备:", chemicalData.getFhzb()));
        baseListBean.getList().add(new BaseListData("泄露处理:", chemicalData.getXlcl()));
        baseListBean.getList().add(new BaseListData("固体泄露:", chemicalData.getGtxl()));
        baseListBean.getList().add(new BaseListData("溶液泄露:", chemicalData.getRyxl()));
        baseListBean.getList().add(new BaseListData("水体泄露:", chemicalData.getStxl()));
        baseListBean.getList().add(new BaseListData("灭火剂:", chemicalData.getMhj()));
        baseListBean.getList().add(new BaseListData("一般措施:", chemicalData.getYbcs()));
        baseListBean.getList().add(new BaseListData("储罐火灾:", chemicalData.getCghz()));
        baseListBean.getList().add(new BaseListData("储罐、公路/铁路、槽车火灾:", chemicalData.getCchz()));
        baseListBean.getList().add(new BaseListData("解毒剂:", chemicalData.getJdj()));
        baseListBean.getList().add(new BaseListData("皮肤接触:", chemicalData.getPfjc()));
        baseListBean.getList().add(new BaseListData("眼睛接触:", chemicalData.getYjjc()));
        baseListBean.getList().add(new BaseListData("吸入:", chemicalData.getXr()));
        baseListBean.getList().add(new BaseListData("食入:", chemicalData.getSr()));
        baseListBean.getList().add(new BaseListData("备注:", chemicalData.getRemark()));
        mRecyclerView.setAdapter(new MyAdapterList(baseListBean));

    }


    public class MyAdapterList extends RecyclerView.Adapter<MyAdapterList.ViewHolder> {

        BaseListDataListBean listBean;

        public MyAdapterList(BaseListDataListBean listBean) {
            this.listBean = listBean;
        }

        //创建新View，被LayoutManager所调用
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.base_list_info_list_item_child, viewGroup, false);
            return new ViewHolder(view);
        }

        //将数据与界面进行绑定的操作
        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int position) {
            viewHolder.bind(position);
        }

        //获取数据的数量
        @Override
        public int getItemCount() {
            int count = listBean == null ? 0 : listBean.getList().size();
            return count;
        }

        //自定义的ViewHolder，持有每个Item的的所有界面元素
        public class ViewHolder extends RecyclerView.ViewHolder {
            @BindView(R.id.text_name)
            TextView text_name;
            @BindView(R.id.text_value)
            TextView text_value;

            public ViewHolder(View view) {
                super(view);
                ButterKnife.bind(this, view);
            }

            public void bind(int position) {
                BaseListData data = listBean.getList().get(position);
                text_name.setText("" + data.getId());
                text_value.setText("" + data.getName() == null ? "" : data.getName());
            }
        }
    }
}
